home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / tsr21src.arc / DEVICE.PAS next >
Pascal/Delphi Source File  |  1986-07-20  |  7KB  |  200 lines

  1. {
  2.   unknown author.
  3.   distributed with TSR Utilities Source code for completeness.
  4. }
  5.  
  6. Program Device_Chain;
  7.  
  8. type
  9.  
  10.   {===========================================================================
  11.     This data type defines the structure of the PC-DOS/MS-DOS File Control
  12.     Block and is used by this program to access the pointer to the NUL
  13.     device which heads the chain of device driver entries.
  14.  
  15.     Most of the record is illustrated for documentation and completeness.
  16.     The actual part that is used to access the device driver chain is listed
  17.     in the documentation as "reserved".  Note (in the comments below) that
  18.     the actual location of this pointer in the FCB is different under versions
  19.     2.x and 3.x of the DOS operating system.
  20.   }
  21.  
  22.   FileControlBlock =
  23.     Record
  24.       Drive     : Byte;
  25.       Filename  : Array [1..8] of char;
  26.       Extension : Array [1..3] of char;
  27.       CurrentBl : Integer;
  28.       LRL       : Integer;
  29.       FilSizeLo : Integer;
  30.       FilSizeHi : Integer;
  31.       FileDate  : Integer;
  32.       FileTime  : Integer;
  33. {-----------------------------------------------------------------------------
  34.   For DOS 3.0 and later, the FCB Structure should be as follows:
  35.   remove the alternate braces from the following code segment and
  36.   delete the similar code segment which follows it.
  37. }
  38. {-----------------------   MS/PC-DOS Version 3.x   ---------------------------}
  39.  
  40.       dummy1    : Integer;
  41.       DevOffset : Integer;
  42.       DevSegment: Integer;
  43.       dummy2    : Byte;
  44.       dummy3    : Byte;
  45.  
  46. {-----------------------   MS/PC-DOS Version 2.x   ---------------------------}
  47. (*
  48.       dummy1    : Byte;
  49.       DevOffset : Integer;
  50.       DevSegment: Integer;
  51.       dummy2    : Integer;
  52.       dummy3    : Byte;
  53. *)
  54. {-----------------------------------------------------------------------------}
  55.  
  56.       CurRecord : Byte;
  57.       RelRecLo  : Integer;
  58.       RelRecHi  : Integer;
  59.     End;
  60. {=============================================================================}
  61.  
  62.   DeviceHeader =
  63.     Record
  64.       NextHeaderOffset : Integer;   { Offset address of next device in chain  }
  65.       NextHeaderSegment: Integer;   { Segment address of next device in chain }
  66.       Attributes       : Integer;   { Device attributes                       }
  67.       StrategyEntPt    : Integer;   { Offset w/i current segment - stragegy   }
  68.       InterruptEntPt   : Integer;   { Offset w/i current segment - interrupt  }
  69.       DeviceName       : Array [1..8] of char;  { Name of the device          }
  70.     End;
  71.  
  72.   Registers =
  73.     Record
  74.       AX, BX, CX, DX, BP, SI, DI, DS, ES, Flags : Integer;
  75.     End;
  76.  
  77.  
  78.   Str80 = String[80];
  79.  
  80.  
  81. var
  82.   DeviceControlBlock : FileControlBlock;  { File Control Block for NUL Device }
  83.   Regs               : Registers;         { Machine registers for MS-DOS calls}
  84.   DevicePtr          : ^DeviceHeader;     { Pointer to the next device header }
  85.   DeviceSegment      : integer;           { Track the device segment and      }
  86.   DeviceOffset       : integer;           {    offset while manipulating chain}
  87.  
  88.  
  89. {-----------------------------------------------------------------------------
  90.   HexStr: Converts the integral value passed by the parameter "number" to a
  91.           string of four hexidecimal character digits.
  92. ------------------------------------------------------------------------------}
  93.  
  94. function HexStr ( number : integer ) : Str80;
  95. const
  96.   HexChars : Array[0..15] of char = '0123456789ABCDEF';
  97. var
  98.   i        : Integer;
  99.   temp     : Str80;
  100. begin  { function HexStr }
  101.   temp[0] := #4;
  102.   for i := 1 to 4 do
  103.     begin
  104.       temp[5-i] := HexChars[ (number and $000F) ];
  105.       number := number shr 4;
  106.     end;
  107.   HexStr := temp;
  108. end;  { function HexStr }
  109.  
  110.  
  111. {-----------------------------------------------------------------------------
  112.   WritePtr: Takes the two integer paramters and prints them in segment
  113.             address format, i.e. SSSS:OOOO
  114. ------------------------------------------------------------------------------}
  115.  
  116. Procedure WritePtr( PtrSeg, PtrOfs : integer );
  117. begin
  118.   Write( HexStr(PtrSeg), ':', HexStr(PtrOfs), '   ');
  119. end;
  120.  
  121.  
  122. begin  { Main program Device_Chain }
  123.  
  124.   LowVideo;
  125.   ClrScr;
  126.   GotoXY(24,1);
  127.   Write('Device Driver');
  128.   GotoXY(20,2);
  129.   Write('Resident Header Chain');
  130.   GotoXY(1,5);
  131.  
  132.   Writeln(' Starting      Next             Strategy   Interrupt   Device');
  133.   Writeln(' Address     Hdr Addr   Attr   Entry Pnt   Entry Pnt   Name');
  134.   Writeln('---------   ---------   ----   ---------   ---------   --------');
  135.  
  136.   {
  137.     Initialize the FCB to zero and set up the NUL device driver name.  Then,
  138.     attempt to open the device for input.  If the open is successful, the
  139.     proper device driver pointer addresses are automatically put in the FCB
  140.     for our use in the rest of the program.
  141.   }
  142.  
  143.   FillChar(DeviceControlBlock,Sizeof(DeviceControlBlock),0);
  144.   With DeviceControlBlock do
  145.     begin
  146.       Filename := 'NUL     ';
  147.       Extension:= '   ';
  148.       With Regs do
  149.         begin
  150.           AX := $0F00;
  151.           DX := Ofs(DeviceControlBlock);
  152.           DS := Seg(DeviceControlBlock);
  153.           MSDos(Regs);
  154.           If (AX and $00FF) <> 0
  155.             then
  156.               begin
  157.                 Writeln('Error in opening the NUL Device');
  158.                 Halt;
  159.               end;
  160.         end;
  161.       DevicePtr     := Ptr(DevSegment,DevOffset);
  162.       DeviceSegment := DevSegment;
  163.       DeviceOffset  := DevOffset;
  164.     end;
  165.  
  166.   {
  167.     Once the proper addresses have bee established, move backward through the
  168.     device driver chain, printing the pertinent data as we proceed.  The end of
  169.     the device driver chain is indicated when the "next device offset" address
  170.     is equal to -1 ($FFFF).
  171.   }
  172.  
  173.   While DeviceOffset <> $FFFF do
  174.     With DevicePtr^ do
  175.       begin
  176.         WritePtr(DeviceSegment,DeviceOffset);
  177.         WritePtr(NextHeaderSegment,NextHeaderOffset);
  178.         Write(HexStr(Attributes), '   ');
  179.         WritePtr(DeviceSegment,StrategyEntPt);
  180.         WritePtr(DeviceSegment,InterruptEntPt);
  181.  
  182.         {
  183.           If the device is a character device (the statement below is TRUE),
  184.           then the "device name" is a valid 8 character representation.  If
  185.           the device is a block device (i.e., a disk drive, etc.) then this
  186.           field usually contains a number indicating how many devices are
  187.           supported by the driver.
  188.         }
  189.  
  190.         if (Attributes and $8000) <> 0
  191.           then Write(DeviceName)
  192.           else Write(Ord(DeviceName[1]),' Block Device Units');
  193.         Writeln;
  194.         DevicePtr     := Ptr(NextHeaderSegment,NextHeaderOffset);
  195.         DeviceSegment := NextHeaderSegment;
  196.         DeviceOffset  := NextHeaderOffset;
  197.       end; { With DevicePtr^ }
  198.  
  199. end.  { Device_Chain }
  200.